#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e6+10;
const int mod = 1e9+7;
long long fib[maxn];
long long ans[maxn];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		string s,k;
		cin>>s;
		fib[0] = 1;
		fib[1] = 1;
		int cnt = 0;
		for(int i = 2;i<=n;i++)
		{
			cin>>k;
			if(k!=s) 
			{
				if(fib[i-1]==1) fib[i]=2;
				else fib[i] = (fib[i-1]+fib[i-2])%mod;
			}
			else 
			{
				fib[i] = 1;
				//if(fib[i-1]!=1) ans[cnt++] = fib[i-1];
			}
			s = k;
		}
	//	printf("**********\n");
		for(int i = 1;i<n;i++)
		{
		
			if(fib[i+1]==1) 
			{
				//printf("***********\n");
				ans[cnt++] = fib[i];
			}
			
		}
		ans[cnt++] = fib[n];
	//	printf("%d\n",cnt);
		long long res = 1;
		for(int i = 0;i<cnt;i++)
		{
			 res = (res*ans[i])%mod;
		}
		printf("%lld\n",res);
	}

} 
